<?php
	class POCO extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model('PO_model_1','PO');
			$this->load->model('User_model','User');
			$this->load->model('Cabang_model','Cabang');
			$this->load->model('Penjualan_model','Penjualan');
		}
		function index(){
			redirect('PO');
			//$this->load->view('halaman/po');
		}
		function PO_INSERT(){
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
				
			$data['intid_week']	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			$data['intid_cabang']	=	$cabang[0]->intid_cabang;
				
				$data['halaman']	=	"po";
				$data['barang']	=	$this->PO->get_barang();
				
				$data['no_po']	=	$this->PO->get_nopo($data['intid_cabang'],$data['intid_week'],'PO');
				/*
				$this->load->view('halaman/head');
				$this->load->view('halaman/header');
				$this->load->view('halaman/js',$data);
				$this->load->view('halaman/index',$data);
				*/
				$this->load->view('halaman/po_header',$data);				
				$this->load->view('halaman/js',$data);				
				$this->load->view('halaman/po_hal1',$data);				
			}
		function proses_po(){
			if($_POST){
				//echo "Loading...<br />";
				$data = array('no_po' => $this->input->post('no_po'),
								'intid_cabang' => $this->input->post('intid_cabang'),
								'intid_week' => $this->input->post('intid_week'),
								);
				$this->db->trans_start();
				$this->PO->insert_DataPO(1,$data);
				$this->db->trans_complete();
				
				$barang = $this->input->post('barang');
				for($i=0;$i<sizeof($barang);$i++){
					if(isset($barang[$i]['intquantity']) and $barang[$i]['intquantity'] != 0){
						$data = array('no_po' => $barang[$i]['no_po'],
										'intid_barang' => $barang[$i]['intid_barang'],
										'quantity' => $barang[$i]['intquantity'],
										'status'	=> 1,
										'keterangan' => $barang[$i]['keterangan']);
						$this->PO->insert_DataPO(2,$data);
						$this->db->trans_complete();
						}
					}
				//echo "Done...!";
				if($this->db->trans_status() == FALSE){
					$this->db->trans_rollback();
					redirect('PO ');
				}else{
					$this->db->trans_commit();
					redirect('POCO/get_PO/?no='.$this->input->post('no_po'));
					}
				}else{
					redirect('home');
					}
			}
		function get_PO(){
			$no = $this->input->get('no');
			if($no !=''){
				$query	=	$this->PO->OpenDB('select pod.*,
									  b.strnama,
									  (select strnama_cabang 
									   	from cabang c inner join po_ po on po.intid_cabang = c.intid_cabang where po.no_po = pod.no_po group by c.intid_cabang) strnama_cabang,
									  (select time 
									   	from  po_ po where po.no_po = pod.no_po group by po.no_po) timeNow,
									  b.intid_jsatuan
									  from po_detail_ pod inner join barang b on b.intid_barang = pod.intid_barang  
									  where pod.no_po = "'.$no.'" order by b.strnama asc');
				$data['query'] = $query->result();
				}else{
					$data['query'] = $this->PO->DataPO();
				}
			$this->load->view('halaman/test',$data);
			
			}
		function DataSPKB(){
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
			//pagination
			$hal = $this->input->get('per_page');
			if($hal == "" or !isset($hal)){
				$hal = 0;
			}
			$limit = 15;
				
				$query = $this->PO->OpenDB('select count(*) total from spkb inner join cabang on cabang.intid_cabang = spkb.intid_cabang 
														where spkb.no_sj = ""');
					$result = $query->result();
					$total = $result[0]->total;
					
				$this->load->library('pagination');
				$config['base_url']  = base_url()."POCO/DataSPKB/?cabang=0";
				$config['total_rows']	=	$total;
				$config['per_page'] 	=	$limit;
				$config['num_links']	=	6;
				$config['first_link']	=	"awal ";
				$config['last_link']	=	"akhir";
				$config['page_query_string'] = TRUE;
				$this->pagination->initialize($config);
				$data['pagination'] = "<div align='center' style='display:block;margin:5px auto 5px auto;width:100%; height:10px;'>".$this->pagination->create_links()."</div>";
				
			
			//pagination
			$data['intid_week']	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			$data['intid_cabang']	=	$cabang[0]->intid_cabang;
			$var =	"";
			$var .= "<div><form method='".base_url()."POCO/SPKB_INSERT_SEARCH/'>Masukan nama cabang<input type='text' name='cabang' size='20' /><input type='submit' name='bttnsubmit' value='search' /></form></div>";
			$var .= $data['pagination'];
			$query = $this->PO->OpenDB('select spkb.*,spkb.time waktu,(select strnama_cabang from cabang where cabang.intid_cabang= spkb.intid_cabang)strnama_cabang from spkb where no_sj is NOT NULL order by waktu desc limit '.$hal.','.$limit.'');
			
			$var .= "<table border='1' style='background:#FFF;' width='100%'>";
			$var .= "<tr>
				<th>No.</th>
				<th>CABANG</th>
				<th>TIME</th>
				<th>NO SPKB</th>
				<th>ACTION</th>
			</tr>";
			$no = 1;
			foreach($query->result() as $row){
				$var .='<tr>
					<td> '.$no++.'.</td>
					<td>'.$row->strnama_cabang.'</td>
					<td>'.$row->waktu.'</td>
					<td>'.$row->no_spkb.'</td>
					<td><a href="'.base_url().'POCO/GET_SPKB/?no='.$row->no_spkb.'">View</a></td>
				</tr>';
				}
			$var .= "<tr>
				<td colspan = '4'>&nbsp;</td>
			</tr>";
			$var .="</table>";
			$var .= $data['pagination'];
			
			$data['tampilan'] =	$var;
			$data['url'] = "";
			$this->load->view('halaman/po_header',$data);
			$this->load->view('halaman/SPKB_hal2',$data);
			}
		function DataSPKB_SEARCH(){
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
			//pagination
			$hal = $this->input->get('per_page');
			if($hal == "" or !isset($hal)){
				$hal = 0;
			}
			$limit = 15;
			//post data from DataSPKB
				if($_POST){
					$varcabang = $this->input->post('cabang');
				}else{
					$varcabang = $this->input->get('cabang');
				}
				$query = $this->PO->OpenDB('select count(*) total from spkb inner join cabang on cabang.intid_cabang = spkb.intid_cabang 
														where spkb.no_sj = "" and cabang.strnama like "'.$varcabang.'%"');
					$result = $query->result();
					$total = $result[0]->total;
					
				$this->load->library('pagination');
				$config['base_url']  = base_url()."POCO/DataSPKB_SEARCH/?cabang=".$varcabang."";
				$config['total_rows']	=	$total;
				$config['per_page'] 	=	$limit;
				$config['num_links']	=	6;
				$config['first_link']	=	"awal ";
				$config['last_link']	=	"akhir";
				$config['page_query_string'] = TRUE;
				$this->pagination->initialize($config);
				$data['pagination'] = "<div align='center' style='display:block;margin:5px auto 5px auto;width:100%; height:10px;'>".$this->pagination->create_links()."</div>";
				
			
			//pagination
			$data['intid_week']	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			$data['intid_cabang']	=	$cabang[0]->intid_cabang;
			$var =	"";
			$query = $this->PO->OpenDB('select spkb.*,spkb.time waktu,b.strnama_cabang from spkb inner join cabang b on b.intid_barang = spkb.intid_barang where no_sj is NOT NULL and b.strnama like "'.$varcabang.'%" order by waktu desc limit '.$hal.','.$limit.'');
			
			$var .= "<table border='1' style='background:#FFF;' width='100%'>";
			$var .= "<tr>
				<th>No.</th>
				<th>CABANG</th>
				<th>TIME</th>
				<th>NO SPKB</th>
				<th>ACTION</th>
			</tr>";
			$no = 1;
			foreach($query->result() as $row){
				$var .='<tr>
					<td> '.$no++.'.</td>
					<td>'.$row->strnama_cabang.'</td>
					<td>'.$row->waktu.'</td>
					<td>'.$row->no_spkb.'</td>
					<td><a href="'.base_url().'POCO/GET_SPKB/?no='.$row->no_spkb.'">View</a></td>
				</tr>';
				}
			$var .= "<tr>
				<td colspan = '4'>&nbsp;</td>
			</tr>";
			$var .="</table>";
			$data['tampilan'] =	$var;
			$data['url'] = "";
			$this->load->view('halaman/po_header',$data);
			$this->load->view('halaman/SPKB_hal2',$data);
			}
		function SPKB_INSERT(){
			$week = $this->Penjualan->selectWeek();
			$var = "";
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
			$temp = "";	
			$intid_week	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			$intid_cabang	=	$cabang[0]->intid_cabang;
				
			$query = $this->PO->openDB('select *,po.time waktu,(select strnama_cabang from cabang where intid_cabang = po.intid_cabang )strnama_cabang 
																from po_ po where 
																	 po.is_sj = 0 and (po.no_spkb is NULL or po.no_spkb = "") order by time desc LIMIT 0, 10');
			
			$var = "<form method='post' action='".base_url()."POCO/SPKB'>";
					$var .= "<br/>
					<table border='1' width='100%' style='background-color:#FFF'>";
					$var .= "<tr>
						<th width='25%'>Cabang</th>
						<th width='35'>Week</th>
						<th width='25%'>Nomor PO</th>
						<th width='35'>Waktu PO</th>
						<th>Action</th>
						</tr>";
					foreach($query->result() as $rok){
						$temp .= "<tr>
							<td align='center'>".$rok->strnama_cabang."</td>
							<td align='center'>".$rok->intid_week."</td>
							<td align='right'>".$rok->no_po."</td>
							<td align='center'>".$rok->waktu."</td>
							<td><a href='".base_url()."POCO/get_PO/?no=".$rok->no_po."'>VIEW</a></td>
							</tr>";
						}
						if($temp != ""){
							$var .= $temp;
							//$var .= "<tr><td colspan='5' align='right'><input type='submit' name='submit' value='LIHAT PO' /></td></tr>";
					}else{
								$var .= "<tr><td colspan='5'>TIDAK ADA PO!</td></tr>";
								}
					$var .= "</table></form>";
			
			$data['intid_week']	=	$week[0]->intid_week;
			
			$data['tampilkan'] = $var;
			$this->load->view('halaman/po_header',$data);
			//$this->load->view('halaman/method_spkb',$data);
			$this->load->view('halaman/SPKB_hal1',$data);
			
		}
		//AJAX CALL
		function FORM_SPKB_RESULT(){
			$var = "Akses Dilarang!! Contact Admin Pusat!";
			$temp = "";
			$ajax	=	$this->input->post('ajax');
			$strnama_cabang = $this->input->post('strnama_cabang');
			$intid_week = $this->input->post('intid_week');
			//Ajax Time 
			if($ajax == 1){
				$cabang	=	$this->User->getCabang($strnama_cabang);			
				$intid_cabang = $cabang[0]->intid_cabang;
				$query = $this->PO->openDB('select *,po.time waktu,(select strnama_cabang from cabang where intid_cabang = '.$intid_cabang.')strnama_cabang from po_ po where po.intid_cabang = '.$intid_cabang.' 
																	and po.is_sj = 0 and (po.no_spkb is NULL or po.no_spkb = "")order by time ASC');
					$var = "<form method='post' action='".base_url()."POCO/SPKB'>";
					$var .= "<h2>PO ".$strnama_cabang.", week : ".$intid_week."</h2><table border='1' width='100%' style='background-color:#FFF'>";
					$var .= "<tr>
						<th width='10%'>Pilih</th>
						<th width='25%'>Cabang</th>
						<th width='35'>Week</th>
						<th width='25%'>Nomor PO</th>
						<th width='35'>Waktu PO</th>
						<th>Action</th>
						</tr>";
					foreach($query->result() as $rok){
						$temp .= "<tr>
							<td align='center'><input type='checkbox' name='po[]' value='".$rok->no_po."' /></td>
							<td align='center'>".$rok->strnama_cabang."</td>
							<td align='center'>".$rok->intid_week."</td>
							<td align='right'>".$rok->no_po."</td>
							<td align='center'>".$rok->waktu."</td>
							<td><a href='".base_url()."POCO/get_PO/?no=".$rok->no_po."'>VIEW</a></td>
							</tr>";
						}
						if($temp != ""){
							$var .= $temp;
							$var .= "<tr><td colspan='6' align='right'><input type='submit' name='submit' value='LIHAT PO' /></td></tr>";
					}else{
								$var .= "<tr><td colspan='6'>TIDAK ADA PO!</td></tr>";
								}
					$var .= "</table></form>";
					echo $var;
				}else{
					echo $var;
				}
			}
		function SPKB(){
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
				
			$data['intid_week']	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			//$data['intid_cabang']	=	$cabang[0]->intid_cabang;
			
			$arr	= array();
			$data['input_type']	= "";
			$po		= $this->input->post('po');
			$no_po	=	array();
			$query0 = $this->PO->OpenDB('select intid_cabang, (select strnama_cabang from cabang where intid_cabang = po.intid_cabang) strnama_cabang from po_ po where po.no_po = "'.$po[0].'"');
			$rock= $query0->result();
			
			$data['no_SPKB']	=	$this->PO->get_nopo($rock[0]->intid_cabang,$data['intid_week'],'SPKB');
			$data['strnama_cabang'] = $rock[0]->strnama_cabang;
			$data['intid_cabang'] = $rock[0]->intid_cabang;
			for($i=0;$i<sizeof($po);$i++){
				$data['input_type']	.=	"<input type='hidden' name='PO[".$i."]' value='".$po[$i]."' />";
				if($po[$i] != ''){
					$query = $this->db->query('select pod.*, b.strnama, b.intid_jsatuan from po_detail_ pod inner join barang b on b.intid_barang = pod.intid_barang where pod.no_po = "'.$po[$i].'" order by b.strnama asc');
					foreach($query->result() as $row){
							$arr[] = array('intid_barang' => $row->intid_barang,
										   'strnama'	=>$row->strnama,
										   'quantity'	=> $row->quantity,
										   'intid_jsatuan' => $row->intid_jsatuan,
										   'keterangan' => $row->keterangan,
										   'no_po' => $po[$i]);
						}
					}
				}
				$data['arr']	=	$arr;
				$data['po']	=	$po;
				///////-------
				$this->load->view('halaman/head',$data);
				$this->load->view('halaman/SPKB',$data);
			}
		//proses penginputan SPKB
		function Proses_SPKB(){
			$no_spkb = $this->input->post('SPKB');
			$po	=	$this->input->post('PO');
			$intid_cabang = $this->input->post('intid_cabang');
			$week = $this->input->post('intid_week');
			
			$namaBarang	= $this->input->post('namaBarang');
			$intidBarang= $this->input->post('intidBarang');
			$quantity	= $this->input->post('quantity');
			$keterangan	= $this->input->post('keterangan');
			
			$this->db->trans_start();
			$this->db->query('insert into spkb values("'.$no_spkb.'", "", "'.date('Y-m-d H:i:s').'","","","","'.$week.'","'.$intid_cabang.'","","")');
			$this->db->trans_complete();
				for($i=0;$i<sizeof($intidBarang);$i++){
				$this->db->query('insert into spkb_detail values ("'.$no_spkb.'", "'.$intidBarang[$i].'","'.$quantity[$i].'","'.$keterangan[$i].'")');
				$this->db->trans_complete();
				}
			
			for($i=0;$i<sizeof($po);$i++){
				$select = 'update po_ set no_spkb="'.$no_spkb.'" where no_po = "'.$po[$i].'"';
				//echo $select."<br />";
				$this->db->query($select);
				$this->db->trans_complete();
				}
				if($this->db->trans_status() == FALSE){
					$this->db->trans_rollback();
					redirect('POCO/SPKB_INSERT');
				}else{
					$this->db->trans_commit();
					redirect('POCO/GET_SPKB/?no='.$no_spkb.'');
					}
			}
		function GET_SPKB(){
			$no_spkb	= $this->input->get('no');
			$var	=	"";
			$query	= $this->PO->openDB('select spb.*,b.strnama,b.intid_jsatuan from spkb_detail spb inner join barang b on b.intid_barang = spb.intid_barang where spb.no_spkb = "'.$no_spkb.'" and spb.quantity != 0 order by b.strnama asc');
			$query2	= $this->PO->openDB('select po.no_po,spkb.no_spkb,(select strnama_cabang from cabang where cabang.intid_cabang = spkb.intid_cabang)strnama_cabang, spkb.time waktu from spkb left join po_ po on po.no_spkb = spkb.no_spkb where spkb.no_spkb like "'.$no_spkb.'"');
			$rok = $query2->result();
			$temp = "";
			/*
			if(isset($rok[0]->waktu)){
				$temp = date('d - m - Y',strtotime($rok[0]->waktu));
			}else{
				$temp = "00 - 00 - 0000";
			}
			if(isset($rok[0]->strnama_cabang)){
				$temp2 = strtoupper($rok[0]->strnama_cabang);
			}else{
				$temp2 = "--tidak ada cabang --";
			}
			*/
			if(isset($rok[0]->waktu)){
				$temp = date('d - m - Y',strtotime($rok[0]->waktu));
				}else{
					$temp = "0000-00-00";
				}
				if(isset($rok[0]->strnama_cabang)){
					$temp2 = strtoupper($rok[0]->strnama_cabang);
				}else{
					$temp2 = "";
				}
				$var .= "<table>
			<tr><td>BANDUNG</td><td>,</td><td>".$temp."</td></tr>
			<tr><td><b>CABANG</b></td><td>:</td><td><b>".$temp2."</b></td></tr>
			";
			foreach($query2->result() as $rok){
				$var .= "<tr><td><b>NO PO</b></td><td>:</td><td><b>".$rok->no_po."</b></td></tr>";
				}
			
			$var .= "<tr><td><b>NO SPKB</b></td><td>:</td><td><b style='font-size:20px;'>".$no_spkb."</b></td></tr>";
			$var .="</table>";
			$var .= "<table border='1' width='100%'>";
			$var .="<tr>
					<th rowspan='2'>NO.</th>
					<th rowspan='2'>NAMA BARANG</th>
					<th colspan='2'>JUMLAH</th>
					<th rowspan='2'>KETERANGAN</th>
				</tr>";
			$var .="<tr>
					<th>PCS</th>
					<th>SET</th>
					</tr>";
			$no = 1;
			$total =0;
			$totalQ = 0;
			$totalQ2 = 0;
			foreach($query->result() as $row){
				$var	.=	"<tr>
					<td align='center'>".$no++."</td>
					<td>".$row->strnama."</td>";
				if($row->intid_jsatuan == 2){
					$var .="<td align='center'>".$row->quantity."</td><td align='center'>0</td>";
				}else{
					$var .="<td align='center'>0</td><td align='center'>".$row->quantity."</td>";
				}
					$var.="<td>".strtoupper($row->keterangan)."</td>
				</tr>";
				if($row->intid_jsatuan == 2){
					$totalQ = $totalQ + $row->quantity;
					}else{
					$totalQ2 = $totalQ2 + $row->quantity;
					}
				}	
				$var .= "<tr>
					<td colspan ='2' align='right'>JUMLAH</td>
					<td align='center'><b>".$totalQ."</b></td>
					<td align='center'><b>".$totalQ2."</b></td>
					<td>&nbsp;</td>
				</tr>";
			$var .="</table>";
			$var .="<table width='100%'>
					<tr>
						<td colspan='4'>&nbsp;</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td width='20%' align='center'>ADM GUDANG</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td width='20%' align='center'>(..............................)</td>
					</tr>
				";
			$data['tampilan'] =	$var;
			$data['url'] = base_url()."POCO/GET_EXCEL_SPKB/?no=".$no_spkb."";
			$this->load->view('halaman/print',$data);
			}
		function SJ_INSERT(){
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
				
			$data['intid_week']	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			$data['intid_cabang']	=	$cabang[0]->intid_cabang;
			$hal = $this->input->get('per_page');
			if($hal == "" or !isset($hal)){
				$hal = 0;
			}
			$limit = 15;
				
				$query = $this->PO->OpenDB('select count(*) total from spkb inner join cabang on cabang.intid_cabang = spkb.intid_cabang 
														where spkb.no_sj = ""');
					$result = $query->result();
					$total = $result[0]->total;
					
				$this->load->library('pagination');
				$config['base_url']  = base_url()."POCO/SJ_INSERT/?cabang=0";
				$config['total_rows']	=	$total;
				$config['per_page'] 	=	$limit;
				$config['num_links']	=	6;
				$config['first_link']	=	"awal ";
				$config['last_link']	=	"akhir";
				$config['page_query_string'] = TRUE;
				$this->pagination->initialize($config);
				$data['pagination'] = $this->pagination->create_links();
					
				$data['query']	=	$this->PO->SPKB_SJ($hal,$limit);
				$this->load->view('halaman/po_header');
				$this->load->view('halaman/SJ_hal1',$data);
			}
		//SJ_INSERT SEARCHING
		function SJ_INSERT_SEARCH(){
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
			$data['intid_week']	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			$data['intid_cabang']	=	$cabang[0]->intid_cabang;
			$limit = 15;
				
				if($_POST){							
					$varcabang = $this->input->post('cabang');
					$hal	=	0;
				}else{
					$varcabang = $this->input->get('cabang');
					$hal	=	$this->input->get('per_page');
					if($hal == null){
						$hal = 0;
					}
				}
					$data['query'] = $this->PO->SPKB_SJ_SEARCH($varcabang,$hal,$limit);

					$query = $this->PO->OpenDB('select count(*) total from spkb inner join cabang on cabang.intid_cabang = spkb.intid_cabang 
														where cabang.strnama_cabang like "'.$varcabang.'" and spkb.no_sj = ""');
					$result = $query->result();
					$total = $result[0]->total;
					
				$this->load->library('pagination');
				$config['base_url']  = base_url()."POCO/SJ_INSERT_SEARCH/?cabang=".$varcabang."";
				$config['total_rows']	=	$total;
				$config['per_page'] 	=	$limit;
				$config['num_links']	=	6;
				$config['first_link']	=	"awal ";
				$config['last_link']	=	"akhir";
				$config['page_query_string'] = TRUE;
				$this->pagination->initialize($config);
				$data['pagination'] = $this->pagination->create_links();
				
				
					$this->load->view('halaman/po_header');
					$this->load->view('halaman/SJ_hal1',$data);
			}
		function Proses_SJ(){
				$data['no_spkb']	=	$this->input->get('no');
				
				$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
				$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
				$week = $this->Penjualan->selectWeek();
				
				$data['halaman'] = 'SJ';	
				$data['barang']	=	$this->PO->get_barang();
					
				$data['intid_week']	=	$week[0]->intid_week;
				$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
				
				$query = $this->PO->OpenDB('select intid_cabang, (select strnama_cabang from cabang where cabang.intid_cabang = spkb.intid_cabang) strnama_cabang,
																  (select time waktu from po_ po where po.no_spkb = spkb.no_spkb)tgl_po from spkb where no_spkb = "'.$data['no_spkb'].'"');
				$result = $query->result();
				
				$data['intid_cabang']	=	$result[0]->intid_cabang;
				$data['strnama_cabang_spkb'] = $result[0]->strnama_cabang;
				$data['waktu'] = date('Y-m-d',strtotime($result[0]->tgl_po));
					
				$data['no_po']	=	$this->PO->get_nopo($result[0]->intid_cabang,$data['intid_week'],'SJ');
				$data['query']	=	$this->PO->OpenDB('select spd.*,barang.strnama,barang.intid_jsatuan 
														  from spkb_detail spd inner join barang on barang.intid_barang = spd.intid_barang 
														  where spd.no_spkb="'.$data['no_spkb'].'" and spd.quantity != 0 order by barang.strnama asc');	
				
					
					$this->load->view('halaman/po_header');
					$this->load->view('halaman/js',$data);
					$this->load->view('halaman/SJ_hal2',$data);
					
			}
		function Proses_SJ_Step2(){
			if($_POST){
				$no_sj	=	$this->input->post('no_sj');
				$no_spkb	=	$this->input->post('no_spkb');
				$namaBarang	=	$this->input->post('namaBarang');
				$intid	=	$this->input->post('intid');
				$quantity	=	$this->input->post('quantity');
				$keterangan	=	$this->input->post('keterangan');
				$tgl_order = $this->input->post('tgl_order');
				$tgl_kirim = $this->input->post('tgl_kirim');
				$via	=	$this->input->post('via');
				
				$TnamaBarang	=	$this->input->post('TnamaBarang');
				$Tintid_barang	=	$this->input->post('Tintid_barang');
				$Tquantity	=	$this->input->post('Tquantity');
				$Tketerangan	=	$this->input->post('Tketerangan');
				
				//mulai update data table
				$this->db->trans_start();
				for($i=0; $i<sizeof($intid);$i++){
					//echo $no_spkb.",".$intid[$i].", ".$namaBarang[$i].",".$quantity[$i].",".$keterangan[$i]."<br />";
					$this->PO->OpenDB('update spkb_detail 
									 	set quantity = "'.$quantity[$i].'", keterangan = "'.$keterangan[$i].'"
										where intid_barang = "'.$intid[$i].'" and no_spkb = "'.$no_spkb.'"');
					$this->db->trans_complete();
				}
				//mulai insert
				for($i=0;$i<sizeof($Tintid_barang);$i++){
					//echo $no_spkb.",".$Tintid_barang[$i].", nama : ".$TnamaBarang[$i].",".$Tquantity[$i].",".$Tketerangan[$i]."::T<br />";
					$this->PO->OpenDB('insert into spkb_detail values("'.$no_spkb.'","'.$Tintid_barang[$i].'","'.$Tquantity[$i].'","'.$Tketerangan[$i].'")');
					$this->db->trans_complete();
				}
				//
				$this->PO->OpenDB('update spkb 
									 	set no_sj = "'.$no_sj.'", tgl_order = "'.$tgl_order.'", tgl_kirim = "'.$tgl_kirim.'", via = "'.$via.'"
										where no_spkb = "'.$no_spkb.'"');
				$this->db->trans_complete();
				$query = $this->PO->OpenDB('select no_spkb,intid_barang from spkb_detail where no_spkb ="'.$no_spkb.'" and quantity = 0');
				/*
				//untuk menghapus semua yang quantity spkb_detail ny 0 
				foreach($query->result() as $row){
					$this->PO->OpenDB('delete from spkb_detail where no_spkb = "'.$no_spkb.'" and intid_barang = "'.$row->intid_barang.'"');
					}
				*/
				if($this->db->trans_status() == FALSE){
					$this->db->trans_rollback();
					redirect('POCO/Proses_SJ/?no='.$no_spkb);
				}else{
					$this->db->trans_commit();
					redirect('POCO/GET_SJ/?no_sj='.$no_sj.'&no_spkb='.$no_spkb.'');	
					}
				
				}
		}	
		function Get_Barang(){
			$namaBarang = $this->input->post('namaBarang');
			
			$data['response'] = 'false';
			$query = $this->PO->OpenDB('select * from barang where strnama = "'.$namaBarang.'" and status_barang = 1');
			if( ! empty($query) )
			{
				$data['response'] = 'true';
				$data['message'] = array();
				foreach( $query as $row )
				{
					/*
					 $cabang = $this->User_model->getCabang($this->session->userdata('username'));
					if($cabang[0]->intid_wilayah == 1){
						$hrg = $row->intharga_jawa;
						$pv = $row->intpv_jawa;
						$um = $row->intum_jawa;
						$cicilan = $row->intcicilan_jawa;
					}else{
						$hrg = $row->intharga_luarjawa;
						$pv = $row->intpv_luarjawa;
						$um = $row->intum_luarjawa;
						$cicilan = $row->intcicilan_luarjawa;
					}
					*/
					$data['message'][] = array(
											'id'=>$row->intid_barang,
											'value'=>$row->strnama,
											);
				}
	
			}
	
	
			if('IS_AJAX')
			{
				echo json_encode($data);
	
			}
			else
			{
				$this->load->view('admin_views/autocomplete/index',$data);
			}
		
			}
		function GET_SJ(){
			$data['no_sj']	=	$this->input->get('no_sj');
			$data['no_spkb']	=	$this->input->get('no_spkb');
			$query2 = $this->PO->OpenDB('select intid_cabang, (select strnama_cabang from cabang where cabang.intid_cabang = spkb.intid_cabang) strnama_cabang, spkb.* from spkb where spkb.no_spkb = "'.$data['no_spkb'].'"');
			$rok = $query2->result();
			$var = "";
			/*
			$var = "
			<div style='background:none; width:200px; float:right;'>
			<ul style='list-style-type:none; float:left;'>
				<li>CABANG : ".strtoupper($rok[0]->strnama_cabang)."</li>
				<li>WEEK : ".$rok[0]->week."</li>
				<li>VIA : ".strtoupper($rok[0]->via)."</li>
				<li>TGl PO : ".$rok[0]->tgl_order."</li>
				<li>TGL KIRIM ".$rok[0]->tgl_kirim."</li>
			</ul></div>";
			*/
			$var .= "<div style='margin:0 auto 0 auto;font-size:30px;background:none;width:30%;' align='center'>SURAT JALAN</b><br />
			<c style='font-size:23px;'>".strtoupper($rok[0]->strnama_cabang)."<c></div><br />";
			$var .= "<table style='float:right; background:none; margin: -20px auto 0 auto;'>
				<tr>
					<td>Bandung</td><td>,</td><td>".date('d - m - Y',strtotime($rok[0]->tgl_kirim))."</td>
				</tr>
				<tr>
					<td>WEEK</td><td>:</td><td>".$rok[0]->week."</td>
				</tr>
				<tr>
					<td>VIA</td><td>:</td><td>".strtoupper($rok[0]->via)."</td>
				</tr>
			</table>";
			$query 	=	$this->PO->OpenDB('select spk.*,b.strnama,b.intid_jsatuan from spkb_detail spk inner join barang b on b.intid_barang = spk.intid_barang where spk.no_spkb = "'.$data['no_spkb'].'" and spk.quantity != 0 order by b.strnama asc');
			$var .= '<div style="margin:50px auto auto auto;font-size:20px;">No Surat Jalan : '.$data['no_sj'].'</div>';
			$var .= '<table border="1" width="100%">';
			$var .= '<tr><th rowspan="2">NO SPKB</th>
						<th rowspan="2">NAMA BARANG</th>
						<th colspan="2">JUMLAH</th>
						<th rowspan="2">KETERANGAN</th>
						</tr>';
			$var .= '<tr>
				<th>PCS</th>
						<th>SET</th>
						</tr>';
			$total_Q=0;
			$total_Q2=0;
			$var .= '<tr><td align="center">'.$data['no_spkb'].'</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></h4>';
			
			foreach($query->result() as $row){
				$var .=	"<tr>
					<td>&nbsp;</td>
					<td>".$row->strnama."</td>";
					if($row->intid_jsatuan == 2){
						$var .="<td align='center'>".$row->quantity."</td><td align='center'>0</td>";
						$total_Q = $row->quantity + $total_Q;
					}else{
						$var .="<td align='center'>0</td><td align='center'>".$row->quantity."</td>";
						$total_Q2 = $row->quantity + $total_Q2;
					}
				$var .="<td>".strtoupper($row->keterangan)."</td>
				</tr>";
				}
			
			$var .= '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
			$var .= '<tr>
				<th align = "center" colspan="2">TOTAL PESANAN</th>
				<th>'.$total_Q.'</th>
				<th>'.$total_Q2.'</th>
				<th>&nbsp;</th>
						</tr>';
			$var .= '</table>';
			$var .= '<table width="100%" align="center">
				<tr><td colspan="9">Barang pesanan yang tidak ada di Surat Jalan berarti kondisi barang kosong di kantor pusat.</td></tr>
				<tr><td colspan="9">Barang yang telah dipesan tidak dapat dikembalikan.</td></tr>
				<tr><td colspan="9">Klaim barang hanya kami terima 1 hari dari pengiriman barang, 1 hari dari penerimaan jarak jauh.</td></tr>
				<tr><td colspan="9">Atas perhatian dan kerjasamanya kami ucapkan terima kasih</td></tr>
				<tr><td colspan="9">&nbsp;</td></tr>
				<tr>
				<td>&nbsp;</td>
				<td align="center">PENERIMA</td>
				<td>&nbsp;</td>
				<td align="center">PEMERIKSA</td>
				<td>&nbsp;</td>
				<td align="center">MENGETAHUI</td>
				<td>&nbsp;</td>
				<td align="center">ADM.GUDANG</td>
				<td>&nbsp;</td>
				</tr>
				<tr><td colspan="9">&nbsp;</td></tr>
				<tr><td colspan="9">&nbsp;</td></tr>
				<tr>
				<td>&nbsp;</td>
				<td align="center">(    .................................     )</td>
				<td>&nbsp;</td>
				<td align="center">(    .................................     )</td>
				<td>&nbsp;</td>
				<td align="center">(    .................................     )</td>
				<td>&nbsp;</td>
				<td align="center">(    .................................     )</td>
				<td>&nbsp;</td>
				</tr>
			</table>';
			$data['tampilan'] =	$var;
			$data['url'] = base_url().'POCO/GET_EXCEL_SJ/?no_sj='.$data['no_sj'].'&no_spkb='.$data['no_spkb'].'';
			$this->load->view('halaman/print',$data);
			}
		function DATA_SJ(){
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
				
			$data['intid_week']	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			$data['intid_cabang']	=	$cabang[0]->intid_cabang;
			$var = "";
			$var .= "<table border='1' style='background-color:#FFF;'>";
			$var .= "<tr>
				<th>NO.</th>
				<th>CABANG</th>
				<th>WEEK</th>
				<th>NO</th>
				<th>WAKTU</th>
				<th>ACTION</th>
			</tr>";
			$i = 1;
			$query 	=	$this->PO->OpenDB('select spkb.*,spkb.time waktu,
										  (select strnama_cabang from cabang where cabang.intid_cabang = spkb.intid_cabang) strnama_cabang
										  from spkb where spkb.intid_cabang = "'.$data['intid_cabang'].'" 
										  	and spkb.no_sj IS NOT NULL
											order by waktu desc');			
			foreach($query->result() as $row){
				$var .= "<tr>
					<td>".$i++."</td>
					<td>".$row->strnama_cabang."</td>
					<td>".$row->week."</td>
					<td>".$row->no_sj."</td>
					<td>".$row->waktu."</td>
					<td>##</td>
				</tr>";
				}
			$var .= "</table>";
			$data['tampilan'] = $var;
			$this->load->view('halaman/po_header');
			$this->load->view('halaman/SJ_hal3',$data);
			}
		function GET_EXCEL_SJ(){
			$var = "tidak ad data";
			$no_sj = $this->input->get('no_sj');
			$data['no_sj']	=	$this->input->get('no_sj');
			$data['no_spkb']	=	$this->input->get('no_spkb');
			$query2 = $this->PO->OpenDB('select intid_cabang, (select strnama_cabang from cabang where cabang.intid_cabang = spkb.intid_cabang) strnama_cabang, spkb.* from spkb where spkb.no_spkb = "'.$data['no_spkb'].'"');
			$rok = $query2->result();
			//$var = "no_sj ".$data['no_sj'].", no_spkb ".$data['no_spkb'];
			$var = "
			<div style='display:block; height:80px;'><img src='".base_url()."images/logo.jpg' align='left' /></div>
			<div style='background:none; width:300px; float:right;'>
			<ul style='list-style-type:none; float:left;'>
				<li>CABANG : ".$rok[0]->strnama_cabang."</li>
				<li>WEEK : ".$rok[0]->week."</li>
				<li>Via : ".$rok[0]->via."</li>
				<li>TGl PO : ".$rok[0]->tgl_order."</li>
				<li>TGL Kirim ".$rok[0]->tgl_kirim."</li>
			</ul></div>";
			$query 	=	$this->PO->OpenDB('select spk.*,b.strnama,b.intid_jsatuan from spkb_detail spk inner join barang b on b.intid_barang = spk.intid_barang where spk.no_spkb = "'.$data['no_spkb'].'" and spk.quantity !=0 order by b.strnama asc');
			$var .= '<div style="margin:100px auto auto auto;">No Surat Jalan : '.$data['no_sj'].'</div>';
			$var .= '<table border="1" width="100%">';
			$var .= '<tr><th rowspan="2">NO SPKB / STTB</th>
						<th rowspan="2">Nama Barang</th>
						<th colspan="2">Jumlah</th>
						<th rowspan="2">Keterangan</th>
						</tr>';
			$var .= '<tr>
				<th>PCS</th>
						<th>Set</th>
						</tr>';
			$total_Q=0;
			$total_Q2=0;
			$var .= '<tr><td align="center">'.$data['no_spkb'].'</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></h4>';
			
			foreach($query->result() as $row){
				$var .=	"<tr>
					<td>&nbsp;</td>
					<td>".$row->strnama."</td>";
					if($row->intid_jsatuan == 2){
						$var .="<td align='center'>".$row->quantity."</td><td align='center'>0</td>";
						$total_Q = $row->quantity + $total_Q;
					}else{
						$var .="<td align='center'>0</td><td align='center'>".$row->quantity."</td>";
						$total_Q2 = $row->quantity + $total_Q2;
					}
				$var .="<td>".$row->keterangan."</td>
				</tr>";
				}
			
			$var .= '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
			$var .= '<tr>
				<th align = "center" colspan="2">TOTAL PESANAN</th>
				<th>'.$total_Q.'</th>
				<th>'.$total_Q2.'</th>
				<th>&nbsp;</th>
						</tr>';
			$var .= '</table>';
			$var .= '<table width="100%" align="center">
				<tr><td colspan="9">Barang pesanan yang tidak ada di Surat Jalan berarti kondisi barang kosong di kantor pusat.</td></tr>
				<tr><td colspan="9">Barang yang telah dipesan tidak dapat dikembalikan.</td></tr>
				<tr><td colspan="9">Klaim barang hanya kami terima 1 hari dari pengiriman barang, 1 hari dari penerimaan jarak jauh.</td></tr>
				<tr><td colspan="9">Atas perhatian dan kerjasamanya kami ucapkan terima kasih</td></tr>
				<tr><td colspan="9">&nbsp;</td></tr>
				<tr>
				<td>&nbsp;</td>
				<td align="center">PENERIMA</td>
				<td>&nbsp;</td>
				<td align="center">PEMERIKSA</td>
				<td>&nbsp;</td>
				<td align="center">MENGETAHUI</td>
				<td>&nbsp;</td>
				<td align="center">ADM.GUDANG</td>
				<td>&nbsp;</td>
				</tr>
				<tr><td colspan="9">&nbsp;</td></tr>
				<tr><td colspan="9">&nbsp;</td></tr>
				<tr>
				<td>&nbsp;</td>
				<td align="center">(    .................................     )</td>
				<td>&nbsp;</td>
				<td align="center">(    .................................     )</td>
				<td>&nbsp;</td>
				<td align="center">(    .................................     )</td>
				<td>&nbsp;</td>
				<td align="center">(    .................................     )</td>
				<td>&nbsp;</td>
				</tr>
			</table>';
			
			$data['tampilan'] = $var;
			$this->load->view('halaman/excel',$data);
			}
		function GET_EXCEL_SPKB(){
			$no_spkb	= $this->input->get('no');
			$var	=	"";
			$query	= $this->PO->openDB('select spb.*,b.strnama,b.intid_jsatuan from spkb_detail spb inner join barang b on b.intid_barang = spb.intid_barang where spb.no_spkb = "'.$no_spkb.'"');
			$query2	= $this->PO->openDB('select po.no_po,(select strnama_cabang from cabang where cabang.intid_cabang = po.intid_cabang)strnama_cabang, po.time waktu from po_ po where po.no_spkb = "'.$no_spkb.'"');
			$rok = $query2->result();
			$var = "<div style='display:block; height:80px;'><img src='".base_url()."images/logo.jpg' align='left' /></div>";			
			$var .= "<div style='float:right; margin-right:60px;'>".$rok[0]->waktu."</div><br />"; 
			$var .= "<div style='float:right; margin-right:60px;'>Cabang : ".$rok[0]->strnama_cabang."</div>"; 
			foreach($query2->result() as $rok){
				$var .= "NO PO : ".$rok->no_po."<br/>";
				}
			
			$var .= "<p><b>NO SPKB : ".$no_spkb."</b></p>";
			$var .= "<table border='1' width='100%'>";
			$var .="<tr>
					<th rowspan='2'>No.</th>
					<th rowspan='2'>Nama Barang</th>
					<th colspan='2'>Jumlah</th>
					<th rowspan='2'>Keterangan</th>
				</tr>";
			$var .="<tr>
					<th>PCS</th>
					<th>SET</th>
					</tr>";
			$no = 1;
			$total =0;
			$totalQ = 0;
			$totalQ2 = 0;
			foreach($query->result() as $row){
				$var	.=	"<tr>
					<td>".$no++."</td>
					<td>".$row->strnama."</td>";
				if($row->intid_jsatuan == 2){
					$var .="<td align='center'>".$row->quantity."</td><td align='center'>0</td>";
				}else{
					$var .="<td align='center'>0</td><td align='center'>".$row->quantity."</td>";
				}
					$var.="<td>".$row->keterangan."</td>
				</tr>";
				if($row->intid_jsatuan == 2){
					$totalQ = $totalQ + $row->quantity;
					}else{
					$totalQ2 = $totalQ2 + $row->quantity;
					}
				}	
				$var .= "<tr>
					<td colspan ='2' align='right'>Jumlah</td>
					<td align='center'><b>".$totalQ."</b></td>
					<td align='center'><b>".$totalQ2."</b></td>
					<td>&nbsp;</td>
				</tr>";
			$var .="</table>";
			$var .="<table width='100%'>
					<tr>
						<td colspan='4'>&nbsp;</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td width='20%' align='center'>ADM GUDANG</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td width='20%' align='center'>(..............................)</td>
					</tr>
				";
			$data['tampilan'] =	$var;
			$data['url'] = "";
			$this->load->view('halaman/excel',$data);
		}
		//////////check POINT////////////////////////
		function GET_SURATRETUR(){
			$var = "";
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
				
			$data['intid_week']	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			$data['intid_cabang']	=	$cabang[0]->intid_cabang;
				
				$data['halaman']	=	"SR";
				$data['barang']	=	$this->PO->get_barang();
				
				$data['no_po']	=	$this->PO->get_nopo($data['intid_cabang'],$data['intid_week'],'SRB');
				
				$var .= '<ul style="list-style-type:none; margin:0 auto 50px -30px;">
							<li>Nomor Retur Barang
								<ul style="list-style-type:square;">
									<li style="font:Verdana, Geneva, sans-serif; font-size:18px;"><h3>'.$no_po.'</h3></li>
										</ul>
								</li>
							</ul>';
				$var .='</div><div class="demo1">
							<label for="search" id="search_label">Masukan Nama Barang </label>
							<input id="search" name="search_barang" size="50" />
							<input type="button" name="tambah" value=" + " id="btn_tambah" />
							<label id="label_verify" for="verify"></label>
						</div>';
				$var .= '
					<form method="post" action="POCO/proses_po">
					<input type="hidden" name="no_po" id="no_po" value="<?php echo $no_po;?>" readonly = "true"/>
					<input type="hidden" name="intid_week" value="<?php echo $intid_week;?>" size="2"/>
					<input type="hidden" name="intid_cabang" value="<?php echo $intid_cabang;?>" size="2" />
					<div class="temp_data"></div>
						<div class="description" style="margin:5px; font-size:10px;">
						<p><small>*</small>Barang terhapus jika quantity di-set menjadi 0 (nol)<small>*</small></p>
						</div><!-- End demo-description -->
						<div class="input-submit" style="margin:auto auto 50px auto;"></div>
					</form>
					';
				
				$data['tampilan'] = $var;
				$this->load->view('halaman/po_header',$data);				
				$this->load->view('halaman/js',$data);				
				$this->load->view('halaman/SR_hal1',$data);
			}
//line ikhlas
	/*
	* @param po_look
	* desc :  menampilkan semua po dari cabang-cabang tertentu
	*
	function po_look(){
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
		
		$data['pagination'] = "";
		$data['po'] = $this->Po_model->get_PO_cabang($cabang[0]->intid_cabang);
		$this->load->view('halaman/po_hal2',$data);
		}
	*/
	//
	function menu_sjpusat(){
		$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
		$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
		$week = $this->Penjualan->selectWeek();
				
		$data['intid_week']	=	$week[0]->intid_week;
		$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
		$data['intid_cabang']	=	$cabang[0]->intid_cabang;
	
		$this->load->view('halaman/po_header',$data);				
		$this->load->view('halaman/SJ_hal4');	
	}
	function sj_approved(){
			$cabang	=	$this->User->getCabang($this->session->userdata('username'));			
		$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
		$week = $this->Penjualan->selectWeek();
				
		$data['intid_week']	=	$week[0]->intid_week;
		$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
		$data['intid_cabang']	=	$cabang[0]->intid_cabang;
	
		$query = $this->PO->OpenDB('select * from spkb where spkb.terkirim = 0 
								   	and spkb.intid_cabang = "'.$data['intid_cabang'].'" 
									and spkb.no_sj != "" order by week desc');
		$data['query']	= $query;
		$this->load->view('halaman/po_header',$data);				
		$this->load->view('halaman/SJ_hal5',$data);
		}
	function sj_accept(){
			$week = $this->Penjualan->selectWeek();
			$no = $this->input->get('no');
			$this->db->query('update spkb set terkirim = 1, tgl_terima = "'.date('Y-m-d H:i:s').'", week = "'.$week[0]->intid_week.'" 
																					 where no_sj = "'.$no.'"');
			$this->session->set_flashdata('messages', '<script>window.alert("STOK SUDAH BERTAMBAH")</script>');
			redirect('POCO/sj_approved');
		}
	function print_stock_cab(){
		$this->load->model('Cabang_model');
		$intid_week = $this->input->post('intid_week');
		$intid_cabang = $this->input->post('intid_cabang');
		
		$data['id_cabang'] = $intid_cabang;
		$data['intid_week'] = $intid_week;
		$data['user'] = $this->session->userdata('username');
		$nm_cabang = $this->Cabang_model->select($intid_cabang);

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
            
		$data['query']  =  $this->PO->getLap_Stok_cab_2($intid_cabang,$intid_week);
		$this->load->view('halaman/ST_hal3',$data);
		}
		//look all po
//line ikhlas
	/*
	* @param po_look
	* desc :  menampilkan semua po dari cabang-cabang tertentu
	*/
	function po_look2(){
		$cabang = $this->User->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang->select($cabang[0]->intid_cabang);
		
		$data['pagination'] = "";
		$data['po'] = $this->PO->get_PO_cabang($cabang[0]->intid_cabang);
		$this->load->view('halaman/po_hal3',$data);
	}
	function DARURAT($intid_po){
		//$no_po = "3033/29/PO/07/2013";
		//$query = $this->db->query('select * from po where intid_po = "'.$intid_po.'"');
		$query = $this->db->query('select surat_jalan.* from surat_jalan where intid_sj = "'.$intid_po.'"');
		foreach($query->result() as $row){
		//echo "yeah".$row->intid_po."<br />";
			//$query2 = $this->db->query('select * from po_detail where po_detail.intid_po = '.$row->intid_po.'');
			//foreach($query2->result() as $rok){
				//echo 'insert ignore into po_detail_ values("'.$row->no_po.'","'.$rok->intid_barang.'","'.$rok->qty.'","1","'.$rok->ket.'");<br />';
			//}
		//echo "insert ignore into po_ values('".$row->no_po."','".$row->intid_cabang."',".$row->intid_week.",'','".$row->no_spkb."',".$row->is_sj.");<br />";		
		//echo "insert ignore into spkb values('".$row->no_spkb."','".$row->no_sj."','','".$row->tgl_order."','".$row->tgl_kirim."','".$row->via."','".$row->intid_week."','".$row->intid_cabang."','','');<br />";
		$query2 = $this->db->query('select * from surat_jalan_detail where surat_jalan_detail.intid_sj = '.$row->intid_sj.'');
			foreach($query2->result() as $rok){
				echo 'insert ignore into spkb_detail values("'.$row->no_spkb.'","'.$rok->intid_barang.'","'.$rok->qty.'","'.$rok->ket.'");<br />';
			}
		
		}
	}
	function sjbiasa(){
		$this->load->view('halaman/SJ_hal6');
 	}
	function sjbuat(){
		$cabang	=	$this->User->getCabang($this->input->post('intid_cabang'));			
			$nama_cabang =	$this->Cabang->select($cabang[0]->intid_cabang);
			$week = $this->Penjualan->selectWeek();
				
			$data['intid_week']	=	$week[0]->intid_week;
			$data['strnama_cabang']	=	$nama_cabang[0]->strnama_cabang;
			$data['intid_cabang']	=	$cabang[0]->intid_cabang;
				
				$data['halaman']	=	"po";
				$data['barang']	=	$this->PO->get_barang();
				
				$data['no_po']	=	$this->PO->get_nopo($data['intid_cabang'],$data['intid_week'],'POPUSAT');
				/*
				$this->load->view('halaman/head');
				$this->load->view('halaman/header');
				$this->load->view('halaman/js',$data);
				$this->load->view('halaman/index',$data);
				*/
				$this->load->view('halaman/po_header',$data);				
				$this->load->view('halaman/js',$data);				
				$this->load->view('halaman/po_hal1',$data);				
			
 	}
}
?>